home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_text_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  6KB  |  176 lines

  1. #include "ewl_test.h"
  2.  
  3. static Ewl_Widget *text_button;
  4.  
  5. static void
  6. __destroy_text_test_window(Ewl_Widget *w, void *ev __UNUSED__,
  7.                     void *data __UNUSED__)
  8. {
  9.     ewl_widget_destroy(w);
  10.     ewl_callback_append(text_button, EWL_CALLBACK_CLICKED,
  11.                 __create_text_test_window, NULL);
  12. }
  13.  
  14. static void
  15. __trigger_cb(Ewl_Widget *w __UNUSED__, void *ev __UNUSED__, void *data)
  16. {
  17.     printf("%s\n", (char *)data);
  18. }
  19.  
  20. static void
  21. __trigger_cb_mouse_in(Ewl_Widget *w, void *ev __UNUSED__, void *data __UNUSED__)
  22. {
  23.     Ewl_Text_Trigger *t;
  24.  
  25.     t = EWL_TEXT_TRIGGER(w);
  26.  
  27.     ewl_text_cursor_position_set(EWL_TEXT(t->text_parent), t->pos);
  28.     ewl_text_color_apply(EWL_TEXT(t->text_parent), 255, 0, 0, 255, t->len);
  29. }
  30.  
  31. static void
  32. __trigger_cb_mouse_out(Ewl_Widget *w, void *ev __UNUSED__, void *data __UNUSED__)
  33. {
  34.     Ewl_Text_Trigger *t;
  35.  
  36.     t = EWL_TEXT_TRIGGER(w);
  37.  
  38.     ewl_text_cursor_position_set(EWL_TEXT(t->text_parent), t->pos);
  39.     ewl_text_color_apply(EWL_TEXT(t->text_parent), 0, 0, 0, 255, t->len);
  40. }
  41.  
  42. static void
  43. __key_press(Ewl_Widget *w __UNUSED__, void *ev, void *data __UNUSED__)
  44. {
  45.     Ewl_Event_Key_Up *event;
  46.  
  47.     event = ev;
  48.     if (!strcmp(event->keyname, "s"))
  49.     {
  50.         Ewl_Widget *t;
  51.         char *c;
  52.  
  53.         t = ewl_widget_name_find("text");
  54.         c = ewl_text_selection_text_get(EWL_TEXT(t));
  55.  
  56.         printf("Selection: (%s)\n", c);
  57.         FREE(c);
  58.     }
  59. }
  60.  
  61. void
  62. __create_text_test_window(Ewl_Widget *w, void *ev __UNUSED__,
  63.                     void *data __UNUSED__)
  64. {
  65.     Ewl_Widget *win, *o;
  66.     Ewl_Text_Trigger *trigger;
  67.     int len;
  68.  
  69.     text_button = w;
  70.  
  71.     win = ewl_window_new();
  72.     ewl_window_title_set(EWL_WINDOW(win), "Text Test");
  73.     ewl_window_name_set(EWL_WINDOW(win), "EWL Test Application");
  74.     ewl_window_class_set(EWL_WINDOW(win), "EFL Test Application");
  75.  
  76.     if (w)
  77.     {
  78.         ewl_callback_del(w, EWL_CALLBACK_CLICKED,
  79.                      __create_text_test_window);
  80.         ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW,
  81.                     __destroy_text_test_window, NULL);
  82.     }
  83.     else
  84.         ewl_callback_append(win, EWL_CALLBACK_DELETE_WINDOW,
  85.                     __close_main_window, NULL);
  86.     ewl_widget_show(win);
  87.  
  88.     ewl_callback_append(win, EWL_CALLBACK_KEY_UP, __key_press, NULL);
  89.  
  90.     o = ewl_text_new();
  91.     ewl_widget_name_set(o, "text");
  92.     ewl_text_selectable_set(EWL_TEXT(o), TRUE);
  93.     ewl_container_child_append(EWL_CONTAINER(win), o);
  94.     ewl_widget_show(o);
  95.  
  96.     ewl_text_text_insert(EWL_TEXT(o), "The first bunch of text\n", 0); /* 24 */
  97.  
  98.     ewl_text_cursor_position_set(EWL_TEXT(o), 10);
  99.     ewl_text_color_apply(EWL_TEXT(o), 0, 0, 255, 255, 5);
  100.     ewl_text_text_append(EWL_TEXT(o), "The second bunch of text\n"); /* 25 */
  101.     
  102.     ewl_text_font_size_set(EWL_TEXT(o), 20);
  103.     ewl_text_styles_set(EWL_TEXT(o), EWL_TEXT_STYLE_DOUBLE_UNDERLINE 
  104.                         | EWL_TEXT_STYLE_OUTLINE 
  105.                         | EWL_TEXT_STYLE_SOFT_SHADOW);
  106.     ewl_text_double_underline_color_set(EWL_TEXT(o), 50, 50, 50, 255);
  107.     ewl_text_shadow_color_set(EWL_TEXT(o), 128, 128, 128, 128);
  108.     ewl_text_outline_color_set(EWL_TEXT(o), 200, 200, 200, 200);
  109.     ewl_text_text_append(EWL_TEXT(o), "The third bunch of text\n"); /* 24 */
  110.  
  111.     ewl_text_text_insert(EWL_TEXT(o), "The fourth bunch of text\n", 31); /* 25 */
  112.  
  113.     trigger = ewl_text_trigger_new(EWL_TEXT_TRIGGER_TYPE_TRIGGER);
  114.     ewl_text_trigger_start_pos_set(trigger, ewl_text_length_get(EWL_TEXT(o)));
  115.  
  116.     ewl_text_cursor_position_set(EWL_TEXT(o), ewl_text_length_get(EWL_TEXT(o)));
  117.     ewl_text_styles_set(EWL_TEXT(o), EWL_TEXT_STYLE_NONE);
  118.     ewl_text_text_append(EWL_TEXT(o), "This is the link."); /* 17 */
  119.  
  120.     len = ewl_text_cursor_position_get(EWL_TEXT(o)) - 
  121.             ewl_text_trigger_start_pos_get(trigger);
  122.     ewl_text_trigger_length_set(trigger, len);
  123.  
  124.     ewl_container_child_append(EWL_CONTAINER(o), EWL_WIDGET(trigger));
  125.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_UP, 
  126.             __trigger_cb, "You clicked the trigger, have a cookie.");
  127.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_IN,
  128.             __trigger_cb_mouse_in, NULL);
  129.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_OUT,
  130.             __trigger_cb_mouse_out, NULL);
  131.  
  132.     ewl_text_text_insert(EWL_TEXT(o), "The fifth bunch of text\n", 0); /* 24 */
  133.  
  134.     ewl_text_cursor_position_set(EWL_TEXT(o), 0);
  135.     ewl_text_color_apply(EWL_TEXT(o), 255, 0, 0, 255, 24);
  136.  
  137.     ewl_text_text_insert(EWL_TEXT(o), "The sixth bunch of text\n", 24); /* 24 */
  138.  
  139.     ewl_text_cursor_position_set(EWL_TEXT(o), 43);
  140.     ewl_text_color_apply(EWL_TEXT(o), 0, 255, 0, 255, 14);
  141.  
  142.     ewl_text_cursor_position_set(EWL_TEXT(o), ewl_text_length_get(EWL_TEXT(o)));
  143.     ewl_text_color_set(EWL_TEXT(o), 255, 0, 0, 255);
  144.     ewl_text_text_append(EWL_TEXT(o), "And in red\n"); /* 11 */
  145.  
  146.     ewl_text_color_set(EWL_TEXT(o), 0, 0, 0, 255);
  147.     ewl_text_text_append(EWL_TEXT(o), "Once more with feeling. ");
  148.  
  149.         trigger = ewl_text_trigger_new(EWL_TEXT_TRIGGER_TYPE_TRIGGER);
  150.     ewl_text_trigger_start_pos_set(trigger, ewl_text_length_get(EWL_TEXT(o)));
  151.     
  152.     ewl_text_text_append(EWL_TEXT(o), "This is the multi\n\nline link."); /* 28 */
  153.  
  154.     len = ewl_text_cursor_position_get(EWL_TEXT(o)) - 
  155.             ewl_text_trigger_start_pos_get(trigger);
  156.     ewl_text_trigger_length_set(trigger, len);
  157.  
  158.     ewl_container_child_append(EWL_CONTAINER(o), EWL_WIDGET(trigger));
  159.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_UP, 
  160.             __trigger_cb, "You clicked the multi-line trigger, have a coke.");
  161.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_IN,
  162.             __trigger_cb_mouse_in, NULL);
  163.     ewl_callback_append(EWL_WIDGET(trigger), EWL_CALLBACK_MOUSE_OUT,
  164.             __trigger_cb_mouse_out, NULL);
  165.  
  166.     ewl_text_color_set(EWL_TEXT(o), 255, 0, 255, 255);
  167.     ewl_text_text_append(EWL_TEXT(o), "ONE MORE SEGV");
  168.  
  169. #if 0
  170.     printf("-- DUMP --\n");
  171.     ewl_text_tree_dump((EWL_TEXT(o))->formatting, "");
  172.     printf("-- DUMP DONE --\n");
  173. #endif
  174. }
  175.  
  176.